package com.pay.ioopos.fragment;

import static com.pay.ioopos.AppUtils.speak;
import static com.pay.ioopos.AppUtils.toast;
import static com.pay.ioopos.widget.Tip.TipType.FAIL;
import static com.pay.ioopos.widget.Tip.TipType.SUCCESS;
import static com.pay.ioopos.widget.Tip.TipType.WAIT;

import com.pay.ioopos.R;
import com.pay.ioopos.display.CustomerHolder;
import com.pay.ioopos.fragment.support.BindState;
import com.pay.ioopos.fragment.support.CheckInState;

/**
 * 退款进程抽象类
 * @author    Moyq5
 * @since  2020/3/30 13:56
 */
public abstract class RefundIngAbstract extends TipVerticalFragment implements BindState, CheckInState {


    public RefundIngAbstract() {
        super(WAIT, "正在申请退款");
    }

    @Override
    public void onPause() {
        super.onPause();
        customerHolder().welcome();
    }

    @Override
    public void onError(String msg) {
        toast(msg);
        showRefundFail();
    }

    @Override
    public boolean useNetwork() {
        return true;
    }

    protected void showRefundSubmit() {
        customerHolder().refundStatus(CustomerHolder.RefundProccess.SUBMITED);
        dispatch(SUCCESS, R.string.refund_submit);
        speak(getString(R.string.refund_submit));
    }

    protected void showRefunding() {
        customerHolder().refundStatus(CustomerHolder.RefundProccess.REFUNDING);
        dispatch(WAIT, R.string.refund_refunding);
    }

    protected void showRefundSuccess() {
        customerHolder().refundStatus(CustomerHolder.RefundProccess.SUCCESS);
        dispatch(SUCCESS, R.string.refund_success);
        speak(getString(R.string.refund_success));
    }

    protected void showRefundFail() {
        customerHolder().refundStatus(CustomerHolder.RefundProccess.FAIL);
        dispatch(FAIL, R.string.refund_fail);
        speak(getString(R.string.refund_fail));
    }

}
